package me.youline.dataServer.service.support.file;

import java.io.File;
import java.io.IOException;

import javax.annotation.PostConstruct;

import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FileLocatorManager {

	@Autowired
	private AvatarFileLocator avatarFileLocator;

	@Autowired
	private RecognPicFileLocator recognPicFileLocator;

	@Autowired
	private ContentFileLocator contentFileLocator;

	@Autowired
	private DisplayPicFileLocator displayPicFileLocator;
	
	@Autowired
	private PubMsgSubjectImgFileLocator subjectFileLocator;

	@PostConstruct
	protected void initialize() throws IOException {
		buildDirRootByFileType(avatarFileLocator);
		buildDirRootByFileType(displayPicFileLocator);
		buildDirRootByFileType(contentFileLocator);
		buildDirRootByFileType(recognPicFileLocator);
		buildDirRootByFileType(subjectFileLocator);
	}
	

	/**
	 * 创建指定类型资源存放路径
	 * @param locator
	 * @throws IOException
	 */
	protected void buildDirRootByFileType(FileLocator locator) throws IOException {
		File file = new File(locator.getFileRoot());
		if(!file.exists()){
			FileUtils.forceMkdir(new File(locator.getFileRoot()));
		}
	}

	public AvatarFileLocator getAvatarFileLocator() {
		return avatarFileLocator;
	}

	public RecognPicFileLocator getRecognPicFileLocator() {
		return recognPicFileLocator;
	}

	public ContentFileLocator getContentFileLocator() {
		return contentFileLocator;
	}

	public DisplayPicFileLocator getDisplayPicFileLocator() {
		return displayPicFileLocator;
	}

}
